package com.yenlien.traceyun.control.dao;

import com.yenlien.traceyun.control.entity.CompanyCrop;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by LiuSha on 2020/8/19.
 */
public interface CompanyCropDao extends BaseJpaDao<CompanyCrop> {
    CompanyCrop findById(String id);

    /**
     * 根据id删除
     *
     * @param id
     */
    public void deleteByModelId(String id);

    CompanyCrop findByModelIdAndCompanyId(String modelId, String companyId);

    CompanyCrop findByModelIdAndCompanyIdAndAppId(String modelId, String companyId, String appId);


    @Transactional
    public void deleteByModelIdAndCompanyId(String modelId, String companyId);

    @Transactional
    public void deleteByModelIdAndCompanyIdAndAppId(String modelId, String companyId, String appId);

    public List<CompanyCrop> findByModelId(String modelId);

    public List<CompanyCrop> findByCompanyId(String companyId);

    @Query(value = "SELECT COUNT(*) FROM t_company_crop WHERE company_id = ?1", nativeQuery = true)
    int getCountByCompanyId(String companyId);
}
